﻿using System;
using System.Configuration;
using System.Web;
using System.Collections;
using PlugNT.Common;
using PlugNT.Custom;
using PlugNT.Cms.Model;
using PlugNT.Cms.Core;

namespace PlugNT.Cms.Page
{
    /// <summary>
    ///AdminPage 的摘要说明
    ///所有AdminUI层页面的 page扩展 都直接或间接继承自此类 
    ///前台直接集成   管理页面间接
    ///初始化一些全局参数 （大部分来自webconfig）
    /// </summary>
    public class AdminPage : SitePager
    {
        /// <summary>
        /// 管理员
        /// </summary>
        protected AdminerInfo adminer = null;


        #region 重载方法
        /// <summary>
        /// 重载Load方法
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {

            //判断用户是否过期
            string adminername = WebConfig.SessionAdminer;
            if (Session[adminername] == null)
            {
                Response.Redirect("/Admin/Login.aspx");
            }
            else
            {
                adminer = (AdminerInfo)Session[adminername];
                if (adminer.islock)
                {
                    Response.Redirect("/Admin/Message.aspx?message=您的帐号已被锁定，请尽快与管理员联系！" + "&z=no");
                }
                else
                {
                    //写出客户端
                    string spower = Request.QueryString["a"] == null ? "" : Request.QueryString["a"].Trim();
                    string powercode = this.ToString();
                    if (spower == "powercode")
                    {
                        Response.Write(HtmlLabel.powerCode + powercode + HtmlLabel.powerCode);
                        Response.End();
                    }

                }
            }

            base.OnLoad(e);
        }


        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }

        /// <summary>
        /// 重载OnPreRender方法
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
        }

        /// <summary>
        /// 卸载页面
        /// </summary>
        /// <param name="e"></param>
        protected override void OnUnload(EventArgs e)
        {
            base.OnUnload(e);
        }

        #endregion


        protected void CheckParamte(object[] parmates)
        {
            foreach (var par in parmates)
            {
                if (Request.QueryString[par.ToString()] == null)
                {
                    Response.Redirect("/Admin/Message.aspx?message=您对该页面执行操作失败，请尽快与管理员联系！" + "&z=no");
                    break;
                }
            }

        }

        /// <summary>
        /// 权限检查
        /// </summary>
        protected void CheckPower()
        {
            //检查权限(如果是超级管理员就不用检查权限)
            string powercode = this.ToString();
            string power = this.adminer.power.Trim();
            if (power != "0")
            {
                if (!DataAccess.curGroupAdmin.GetCodeList(power).Contains(powercode + ","))
                {
                    Response.Redirect("/Admin/Message.aspx?message=您没有权限对该页面执行操作，请尽快与管理员联系！" + "&z=no");
                }
            }
        }


    }
}
